﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using Cisoft.Cisoft3G.Model;
namespace Cisoft.Cisoft3G.BLL
{
    /// <summary>
    /// 业务逻辑类DefineGroupBO 的摘要说明。
    /// </summary>
    public class DefineGroupBO
    {
        private readonly Cisoft.Cisoft3G.DAL.DefineGroupDO dal = new Cisoft.Cisoft3G.DAL.DefineGroupDO();
        public DefineGroupBO()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int DG_ID)
        {
            return dal.Exists(DG_ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Cisoft.Cisoft3G.Model.DefineGroupMO model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Cisoft.Cisoft3G.Model.DefineGroupMO model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int DG_ID)
        {

            dal.Delete(DG_ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cisoft.Cisoft3G.Model.DefineGroupMO GetModel(int DG_ID)
        {

            return dal.GetModel(DG_ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public Cisoft.Cisoft3G.Model.DefineGroupMO GetModelByCache(int DG_ID)
        {

            string CacheKey = "DefineGroupMOModel-" + DG_ID;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(DG_ID);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Cisoft.Cisoft3G.Model.DefineGroupMO)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Cisoft.Cisoft3G.Model.DefineGroupMO> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Cisoft.Cisoft3G.Model.DefineGroupMO> DataTableToList(DataTable dt)
        {
            List<Cisoft.Cisoft3G.Model.DefineGroupMO> modelList = new List<Cisoft.Cisoft3G.Model.DefineGroupMO>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Cisoft.Cisoft3G.Model.DefineGroupMO model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Cisoft.Cisoft3G.Model.DefineGroupMO();
                    if (dt.Rows[n]["DG_ID"].ToString() != "")
                    {
                        model.DG_ID = int.Parse(dt.Rows[n]["DG_ID"].ToString());
                    }
                    model.DG_Name = dt.Rows[n]["DG_Name"].ToString();
                    model.DG_GroupMember = dt.Rows[n]["DG_GroupMember"].ToString();
                    if (dt.Rows[n]["US_UserID_FK"].ToString() != "")
                    {
                        model.US_UserID_FK = int.Parse(dt.Rows[n]["US_UserID_FK"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法

        public DataSet GetListWithPage(int pageCurrent, int pageSize, string strWhere)
        {
            return dal.GetListWithPage(pageCurrent, pageSize, strWhere);
        }

        public int GetListCount(int pageCurrent, int pageSize, string strWhere)
        {
            return dal.GetListCount(pageCurrent, pageSize, strWhere);
        }
    }
}

